<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
          name="viewport"/>
    <title></title>
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
    <link rel="stylesheet" href="css/jeicon.css"/>
    <link rel="stylesheet" href="css/framework.css"/>
    <link rel="stylesheet" href="css/publicStyle.css"/>
    <style>
        html, body {
            height: 100%;
            overflow: hidden;
            background: white;
            font-weight: 400;
        }
    </style>
</head>
<body class="blue">
<div id="app">
</div>
<div id="per-loader" class="loader">
    <div class="loader-inner"></div>
</div>
<!--<script src="js/loader.js"></script>-->
<script src="system/config?debug=true"></script>
<script src="js/lib/vue-shim.min.js"></script>
<script src="js/lib/es-module-shims.min.js"></script>
<!--<script type="module-shim" src="js/layout.js"></script>-->
<script>
    // <!--    import {init} from 'framework'-->
    // <!--    import page from -->
    // <!--    init(page).mount('#app')-->

    //let page = await importShim('#(basePath)page#(path)')
    let hash=location.hash.substring(1)
    let path = "." + hash

    if ("." != path) {
        if(path.indexOf("?")>0){
            path+="&source=debug.vue"
        }else{
            path+="?source=debug.vue"
        }
        Promise.all([importShim('framework'), importShim(path),importShim('axios'),importShim('heyui'),importShim('vue-router')])
        .then(([framework, page,axios,HeyUI]) => {
            let message=HeyUI.message
            let showErrHandler

//同时(10纳秒内)发生多个错误时，提示最后一个
            function showError(msg) {
                clearTimeout(showErrHandler)
                showErrHandler = setTimeout(() => {
                    message({type: 'error', text: msg})
                }, 10);
            }
            axios.default.interceptors.response.use(function (res) {

                let headers = res.headers
                let token = headers['token'];
                if (token) {
                    sessionStorage.setItem("_token", token);
                } else if (headers['rtk']) {
                    sessionStorage.removeItem("_token")
                }

                let isJson = res.headers['content-type'].indexOf('json') > -1;
                if (isJson && res.data) {
                    if (res.data.success) {
                        return res.data
                    }
                    let msg = res.data.description || res.data.message;
                    if("success"==msg){
                        return res.data
                    }
                    if (msg) {
                        showError(msg)
                    }
                    // HeyUI.$Message({type: 'error', text: res.data.description})
                    return Promise.reject(res.data)
                } else {
                    if (res.data && res.data.success == false) {
                        return Promise.reject(res.data)
                    }
                    return isJson ? res.data : res;
                }
            }, function (error) {
                // 对响应错误做点什么;没有权限401，去登录界面
                if (!error.response) {
                    showError("网络错误！")
                    //HeyUI.$Message({type: 'error', text: "网络错误！"})
                } else if (error.response.status === 401) {
                    // window.$toast('登录超时')
                    // location.hash = "/login"
                    showError("未登录！")
                } else if (error.response.status === 403) {
                    // window.$toast('暂无权限')
                    //HeyUI.$Message({type: 'error', text: "没有权限！"})
                    showError("没有权限！")
                    // location.hash = "/login"
                } else if (error.response.status === 500) {
                    // window.$toast('网络错误')
                    //HeyUI.$Message({type: 'error', text: "服务器错误！"})
                    showError("服务器错误！")
                } else if (error.response.status === 404) {
                    // window.$toast('网络错误')
                    showError("页面未找到！")
                    // HeyUI.$Message({type: 'error', text: "404 NOT FOUND！"})
                } else if (error.response.data) {
                    let data = error.response.data
                    showError(data.description || data.data || data.message)
                    //HeyUI.$Message({type: 'error', text: data.description||data.data})
                }
                return Promise.reject(error);
            });

            framework.init(page.default)
                .mount('#app')
        })
    }
</script>
</body>
</html>
